package com.gao.cluster.common;

public class Constants {

    /**
     * 结果码值
     */
    public enum ResponseCode {
        SUCCESS("0000", "成功"),
        UN_ERROR("0001", "未知失败"),
        ILLEGAL_PARAMETER("0002", "非法参数"),
        INDEX_DUP("0003", "主键冲突"),
        NO_UPDATE("0004", "SQL操作无更新"),
        LOSING_DRAW("D001", "未中奖"),
        OUT_OF_STOCK("D004", "产品无库存"),
        ERR_TOKEN("D005", "分布式锁失败");

        private String code;
        private String info;

        ResponseCode(String code, String info) {
            this.code = code;
            this.info = info;
        }

        public String getCode() {
            return code;
        }

        public String getInfo() {
            return info;
        }

    }

    /**
     * 缓存 key
     */
    public static final class RedisKey {

        // 产品缓存
        private static final String PRODUCT = "product_";

        // 产品库存 key
        private static final String PRODUCT_STOCK_COUNT = "product_stock_count_";

        // 产品库存锁 key
        private static final String PRODUCT_STOCK_COUNT_LOCK = "product_stock_count_lock_";

        // 产品分布式锁 key
        private static final String PRODUCT_STOCK_REDISSON_LOCK = "product_stock_redisson_lock_";

        public static String getProductStockCount(Long productId) {
            return PRODUCT_STOCK_COUNT + productId;
        }

        public static String getProductStockRedissonLock(Long productId) {
            return PRODUCT_STOCK_REDISSON_LOCK + productId;
        }

        public static String getProductStockCountLock(Long productId, Integer stockUsedCount) {
            return PRODUCT_STOCK_COUNT_LOCK + productId + "_" + stockUsedCount;
        }

        public static String getProductStockRandomLock(Long randowNumeric) {
            return PRODUCT_STOCK_COUNT_LOCK + "_" + randowNumeric;
        }

        public static String getProduct() {
            return PRODUCT;
        }

        public static String getProduct(Long productId) {
            return PRODUCT + "_" + productId;
        }
    }

    /**
     * Ids 生成策略枚举
     */
    public enum Ids {
        /**
         * 雪花算法
         */
        SnowFlake,
        /**
         * 日期算法
         */
        ShortCode,
        /**
         * 随机算法
         */
        RandomNumeric
    }
}
